package com.bot.dev.module.job.task;

import com.bot.common.timer.CommonTimerTaskRunner;
import com.bot.nft.module.dc.domain.DcOrderInfo;
import com.bot.nft.module.dc.domain.DcSellOrderInfo;
import com.bot.nft.module.dc.service.IDcOrderInfoService;
import com.bot.nft.module.dc.service.IDcSellOrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 定时器的一个示例
 *
 * @author botian
 * @date 2022/8/5 15:52
 **/
@Slf4j
@Component
public class OrderTimerTaskRunner implements CommonTimerTaskRunner {

    private int n = 1;

    @Resource
    IDcOrderInfoService dcOrderService;

    @Resource
    IDcSellOrderInfoService dcSellOrderInfoService;

    @Override
    public void action() {
        OrderTimerTaskRunner.log.info("我是一个定时任务，正在在被执行第" + n + "次");
        n = n + 1;
        //这里写下你想要执行的业务逻辑代码
        List<DcOrderInfo> dcOrderInfos = dcOrderService.selectOrder();
        //藏品订单取消
        for (DcOrderInfo dcOrderInfo : dcOrderInfos) {
            Date createTime = dcOrderInfo.getCreateTime();
            //创建一个系统当先时间
            Date date = new Date();
            //计算时间差
            long timeDiff = date.getTime() - createTime.getTime();
            if (timeDiff > 300000) dcOrderService.cancelDcNftInfo(dcOrderInfo.getId());
            else System.out.println(timeDiff);
        }
        //寄售订单定时取消
        List<DcSellOrderInfo> dcSellOrderInfos = dcSellOrderInfoService.selectSellOrder();
        //for循环对比
        for (DcSellOrderInfo dcSellOrderInfo : dcSellOrderInfos) {
            //获取创建时间
            Date createTime = dcSellOrderInfo.getCreateTime();
            //创建一个系统当先时间
            Date date = new Date();
            //计算时间差
            long timeDiff = date.getTime() - createTime.getTime();
            if (timeDiff > 300000) dcSellOrderInfoService.cancelPayOrder(dcSellOrderInfo.getId());
            else System.out.println(timeDiff);
        }
    }
}
